local InternalController = {}
local db = require 'models.db'
local user=require 'library.user'
local page = require 'library.pageobj'
local helper = require 'library.helpers'
local cookie = require ('vanilla.v.libs.cookie'):new()


function InternalController:tags()
    local p = {}
    local links=db:new('links')  
    local tags=db:new('tags')  
    local get = self:getRequest():getParams()

 	get['tag_id'] = get['tag_id'] or 0
    p['links']=links:where('is_show=?',1):get_list()
    p['tags']=tags:get_list()
    p['tag_id']=tonumber(get['tag_id'])

    return self:display(p)
end

function InternalController:login_header()
	local p={}
	p['is_login']=user:is_login()
	if user:is_login() then
		p['user_name']=user:get()['name']
	end
	return self:display(p)
end

function InternalController:comment()
    local p={}
    local page_params={}
    local post=self:getRequest():POST()
    local get=self:getRequest():GET()
    local comments=db:new('comments')  

    page_params["id"]=post['id']
    page_params["page"]=":page:"

    local pageobj = page:new(comments:count(),12,tonumber(get['page']),helper:url('article/index',page_params));
    p['comments']=comments:order('pid desc'):limit(pageobj:limit()):where('aid=?',post['id']):get_list()
    p['article']=post
    p['page']=pageobj

    p['user_name']=cookie:get('user_name')

    return self:display(p)
end

return InternalController
